home *** CD-ROM | disk | FTP | other *** search
- unit FMain; // Copyright ⌐ 1996-2001 Plasmatech Software Design. All rights reserved.
- {
- Shell Control Pack - Demo Program
- Version 1.6
-
- This file is part of the Shell Control Pack demonstration program.
- It implements the main tabbed form.
-
- History
- ===================================================================================================
- V1.6 2Jul01 Delphi 6 release. No changes.
- V1.5c 30Mar01 No changes.
- V1.5b 12Dec00 No changes.
- V1.5a 14May00 No changes.
- V1.5 3Mar00 C++Builder 5 release.
- V1.4a 5Nov99 No changes.
- V1.4 14Sep99 Delphi 5 release. No changes.
- V1.3h 29Mar99 No changes.
- V1.3g 1Dec98 No changes.
- V1.3f 12Jul98 Delphi 4 release. No changes.
- V1.3e 22Apr98 No changes.
- V1.3d 18Apr98 No changes.
- V1.3c 16Mar98 No changes.
- V1.3b 7Feb98 No changes.
- V1.3a 7Jan98 Added hints to toolbar image.
- V1.3 28Nov97 Added internationalisation code.
- V1.2b 12Oct97 No changes.
- V1.2a 5Oct97 No significant changes.
- V1.2 6Sep97 Added aCD.Canvas example to PTTreeView1CustomDraw method.
- V1.1a 6Jul97 No changes.
- V1.1 26Jun97 Added palette support for welcome page.
- Added scrollboxes to the splitter demo.
- Added Custom Draw Tree page.
- V1.0c 31May97 No significant changes.
- V1.0b 17May97 Minor fixes and Delphi 3 support.
- V1.0a 1May97 No significant changes.
- V1.0 21Apr97 Released version 1.0
- }
-
- {$INCLUDE PTCompVer.inc}
-
- {$RANGECHECKS OFF} {$OVERFLOWCHECKS OFF} {$WRITEABLECONST OFF}
- {$BOOLEVAL OFF} {$EXTENDEDSYNTAX ON} {$TYPEDADDRESS ON}
-
- interface
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- StdCtrls, ComCtrls, ExtCtrls, Buttons, Ole2, Menus,
- UPTSplitter, UPTShellControls, UPTShell95, UPTShellUtils, UPTImageCombo,
- FPTOpenDlg, FPTFolderBrowseDlg, UPTTreeList, UPTFrame;
-
-
- type TMaxLogPalette = packed record
- palVersion: Word;
- palNumEntries: Word;
- palPalEntry: array [Byte] of TPaletteEntry;
- end;
- PMaxLogPalette = ^TMaxLogPalette;
-
- // Type used to store data with the tree on the "Custom Draw Tree" page.
- type TTvData = class
- private
- mFont: TFont;
- mBkColor: TColor;
- procedure SetFont( aValue: TFont );
- public
- constructor Create( aFont: TFont; aColor: TColor );
- destructor Destroy; override;
- property Font: TFont read mFont write SetFont;
- property BkColor: TColor read mBkColor write mBkColor;
- end;
-
- type
- TFrmMain = class(TForm)
- PageControl1: TPageControl;
- ExplorerTsh: TTabSheet;
- Button1: TButton;
- SplitterTsh: TTabSheet;
- PTSplitter3: TPTSplitter;
- PTSplitter4: TPTSplitter;
- Label2: TLabel;
- PTSplitter5: TPTSplitter;
- Label3: TLabel;
- ListTsh: TTabSheet;
- WelcomeTsh: TTabSheet;
- PaintBox1: TPaintBox;
- Label1: TLabel;
- Label4: TLabel;
- VersionTxt: TLabel;
- Panel1: TPanel;
- PlasmaLogoImg: TImage;
- Label6: TLabel;
- Label7: TLabel;
- Label8: TLabel;
- Button3: TButton;
- Button5: TButton;
- Button6: TButton;
- Button8: TButton;
- Button9: TButton;
- Label9: TLabel;
- OpenDialogTsh: TTabSheet;
- FolderBrowseTsh: TTabSheet;
- OverviewTsh: TTabSheet;
- Button7: TButton;
- Button4: TButton;
- Button11: TButton;
- Button12: TButton;
- Edit1: TEdit;
- Label10: TLabel;
- TestOpenDlgBtn: TButton;
- Button14: TButton;
- Button15: TButton;
- Button16: TButton;
- Button17: TButton;
- Label11: TLabel;
- PTShellList1: TPTShellList;
- PTOpenDlg1: TPTOpenDlg;
- OverviewRchtxt: TRichEdit;
- ExplorerRchtxt: TRichEdit;
- FileOpenRchedt: TRichEdit;
- TabSheet8: TTabSheet;
- UppercaseEdt: TEdit;
- Label14: TLabel;
- Label15: TLabel;
- GetDisplayEdt: TEdit;
- Button18: TButton;
- Button19: TButton;
- ShellGetDisplayPathnameRchedt: TRichEdit;
- FolderBrowseRchedt: TRichEdit;
- ToolbarImg: TImage;
- PTFolderBrowseDlg1: TPTFolderBrowseDlg;
- FolderBrowseBtn: TButton;
- TabSheet4: TTabSheet;
- ImageComboRchedt: TRichEdit;
- Button2: TButton;
- Button20: TButton;
- PTImageCombo1: TPTImageCombo;
- PTImageCombo2: TPTImageCombo;
- Button13: TButton;
- PTSaveDlg1: TPTSaveDlg;
- OrderTsh: TTabSheet;
- Button21: TButton;
- Button22: TButton;
- OrderBtn: TButton;
- Button23: TButton;
- OrderRchedt: TRichEdit;
- PTTreeTsh: TTabSheet;
- PTTreeView1: TPTTreeView;
- FontBtn: TButton;
- Timer1: TTimer;
- EnableTimerBtn: TSpeedButton;
- CustomDrawTreeRchedt: TRichEdit;
- Button24: TButton;
- Button25: TButton;
- ClickMe1Btn: TButton;
- BoldBtn: TSpeedButton;
- ItalicBtn: TSpeedButton;
- UnderlineBtn: TSpeedButton;
- ScrollBox1: TScrollBox;
- Image3: TImage;
- ScrollBox2: TScrollBox;
- Image1: TImage;
- ResetBtn: TButton;
- PopupMenu1: TPopupMenu;
- LargeIconsMitm1: TMenuItem;
- SmalliconsMItm1: TMenuItem;
- ListMitm1: TMenuItem;
- DetailsMitm1: TMenuItem;
- FontDialog1: TFontDialog;
- FgColorBtn: TButton;
- BkColorBtn: TButton;
- ColorDialog1: TColorDialog;
- BaseBtn: TButton;
- BaseTxt: TLabel;
- Button10: TButton;
- procedure Button1Click(Sender: TObject);
- procedure PaintBox1Paint(Sender: TObject);
- procedure OnNextBtnClick(Sender: TObject);
- procedure OnBackBtnClick(Sender: TObject);
- procedure Button10Click(Sender: TObject);
- procedure FormCreate(Sender: TObject);
- procedure TestOpenDlgBtnClick(Sender: TObject);
- procedure FolderBrowseBtnClick(Sender: TObject);
- procedure PTFolderBrowseDlg1SelChange(aSender: TObject; aNewSel: PItemIDList);
- procedure Button13Click(Sender: TObject);
- procedure OrderBtnClick(Sender: TObject);
- procedure FormDestroy(Sender: TObject);
- procedure EnableTimerBtnClick(Sender: TObject);
- procedure Timer1Timer(Sender: TObject);
- procedure BoldBtnClick(Sender: TObject);
- procedure ItalicBtnClick(Sender: TObject);
- procedure UnderlineBtnClick(Sender: TObject);
- procedure PTTreeView1Deletion(Sender: TObject; Node: TTreeNode);
- procedure ClickMe1BtnClick(Sender: TObject);
- procedure ResetBtnClick(Sender: TObject);
- procedure ViewMitmClick(Sender: TObject);
- procedure FontBtnClick(Sender: TObject);
- procedure FgColorBtnClick(Sender: TObject);
- procedure BkColorBtnClick(Sender: TObject);
- procedure PTTreeView1Change(Sender: TObject; Node: TTreeNode);
- procedure BaseBtnClick(Sender: TObject);
- procedure ToolbarImgMouseMove(Sender: TObject; Shift: TShiftState; X,
- Y: Integer);
- procedure PTTreeView1NodeContextMenu(aSender: TObject;
- aNode: TTreeNode; var aPos: TPoint; var aMenu: TPopupMenu);
- procedure PTTreeView1PTCustomDraw(aSender: TObject; aCD: TPTCustomDraw;
- aNode: TTreeNode);
- private
- procedure LoadRtf( rtf: TRichEdit; id: Integer );
- protected // -- Palette support -----
- mhPal: HPALETTE;
- mPalStruct: TMaxLogPalette;
- function GetPalette: HPALETTE; override;
- procedure WMPaletteChanged( var aMsg: TWMPaletteChanged ); message WM_PALETTECHANGED;
- protected // -- Custom Draw Tree Page ----
- procedure CDT_DoFontStyle( aNode: TTreeNode; aDown: Boolean; aStyle: TFontStyle );
- function CDT_GetNodeData( aNode: TTreeNode ): TTvData;
- procedure CDT_OnDynamicMenuClick( aSender: TObject );
- public
- { Public declarations }
- end;
-
- var
- FrmMain: TFrmMain;
-
- implementation
- uses ShellApi,
- FExplorer;
- {$R *.DFM}
-
- {Create a blue-white wash palette with 64 entries}
- procedure CreatePaletteStruct( var lp: TMaxLogPalette );
- const ENTRIES = 64;
- function PeEntry( r, g, b: Byte ): TPaletteEntry;
- begin
- result.peRed := r;
- result.peGreen := g;
- result.peBlue := b;
- result.peFlags := 0;
- end;
- var i: Integer;
- tp: TColorRef;
- bt: TColorRef;
-
- tr, tg, tb: Integer;
- br, bg, bb: Integer;
- begin
- lp.palVersion := $0300;
- lp.palNumEntries := ENTRIES;
-
- tp := ColorToRGB( clBlue ); bt := ColorToRGB( clWhite );
-
- tr := GetRValue(tp); br := GetRValue(bt);
- tg := GetGValue(tp); bg := GetGValue(bt);
- tb := GetBValue(tp); bb := GetBValue(bt);
-
- for i := 0 to ENTRIES-1 do
- lp.palPalEntry[i] := PeEntry( tr + ((br-tr)*i) div (ENTRIES-1),
- tg + ((bg-tg)*i) div (ENTRIES-1),
- tb + ((bb-tb)*i) div (ENTRIES-1) );
- end; {CreatePaletteStruct}
-
-
- {---------------------------------------------------------}
-
- constructor TTvData.Create( aFont: TFont; aColor: TColor );
- begin
- mFont := TFont.Create;
- mFont.Assign( aFont );
- mBkColor := aColor;
- end;
-
- destructor TTvData.Destroy;
- begin
- mFont.Free;
- inherited;
- end;
-
- procedure TTvData.SetFont( aValue: TFont );
- begin mFont.Assign( aValue ); end;
-
- {---------------------------------------------------------}
-
-
- procedure TFrmMain.Button1Click(Sender: TObject);
- begin
- if not Assigned(FrmExplorer) then FrmExplorer := TFrmExplorer.Create(self);
- FrmExplorer.Show;
- end;
-
-
- { Loads a rich text file from resources into the given rich text control. }
- procedure TFrmMain.LoadRtf( rtf: TRichEdit; id: Integer );
- var rs: TResourceStream;
- begin
- rs := TResourceStream.CreateFromId( HInstance, id, 'RTF' );
- try rtf.Lines.LoadFromStream( rs ); finally rs.Free; end;
- end;
-
-
- function TFrmMain.GetPalette: HPALETTE;
- begin
- result := mhPal;
- end;
-
-
- procedure TFrmMain.WMPaletteChanged( var aMsg: TWMPaletteChanged );
- begin
- if (aMsg.PalChg <> PaintBox1.Parent.Handle) then
- PaintBox1.Invalidate;
- inherited;
- end;
-
-
- {$WARNINGS OFF}
- procedure Wash( aCanvas: TCanvas; ahPalette: HPalette; apPalStruct: PLogPalette; afActive: Boolean;
- aRect: TRect; aFrom, aTo: TColor; afVertical: Boolean );
- type PColorRef=^TColorRef;
- var pPalStruct: PMaxLogPalette absolute apPalStruct;
- i: Integer;
- tp: TColorRef;
- bt: TColorRef;
-
- tr, tg, tb: Integer;
- br, bg, bb: Integer;
-
- rc: TRect;
-
- nDivs: Integer;
-
- oldpal: HPALETTE;
- begin
- if (ahPalette=0) then
- begin
- tp := ColorToRGB( aFrom ); bt := ColorToRGB( aTo );
- tr := GetRValue(tp); br := GetRValue(bt);
- tg := GetGValue(tp); bg := GetGValue(bt);
- tb := GetBValue(tp); bb := GetBValue(bt);
- if afVertical then
- nDivs := (aRect.bottom - aRect.top) div 2 +1
- else
- nDivs := (aRect.right - aRect.left) div 2 +1;
- rc := aRect;
- end
- else
- begin
- oldpal := SelectPalette( aCanvas.Handle, ahPalette, not afActive );
- RealizePalette( aCanvas.Handle );
- rc := aRect;
- nDivs := 64;
- end;
-
- with aCanvas do
- begin
- for i := 0 to nDivs-1 do
- begin
- if (ahPalette=0) then
- Brush.Color := RGB( tr + ((br-tr)*i) div (nDivs-1),
- tg + ((bg-tg)*i) div (nDivs-1),
- tb + ((bb-tb)*i) div (nDivs-1) )
- else
- Brush.Color := $02000000 or PColorRef(@pPalStruct^.palPalEntry[i])^;
- if afVertical then
- begin
- rc.top := ((aRect.bottom - aRect.top)*i) div nDivs;
- rc.bottom := rc.top + (aRect.bottom - aRect.top) div nDivs+1;
- end
- else
- begin
- rc.left := aRect.left + ((aRect.right - aRect.left)*i) div nDivs;
- rc.right := rc.Left + (aRect.right - aRect.left) div nDivs +1;
- end;
- FillRect( rc );
- end;
- end;
-
- if (ahPalette<>0) then
- SelectPalette( aCanvas.Handle, oldpal, TRUE );
- end;
- {$WARNINGS ON}
-
-
- procedure TFrmMain.PaintBox1Paint(Sender: TObject);
- begin
- Wash( PaintBox1.Canvas, mhPal, Pointer(@mPalStruct), Active, PaintBox1.ClientRect, clBlue, clWhite, TRUE );
- end;
-
- procedure TFrmMain.OnNextBtnClick(Sender: TObject);
- begin PageControl1.SelectNextPage(TRUE); end;
-
- procedure TFrmMain.OnBackBtnClick(Sender: TObject);
- begin PageControl1.SelectNextPage(FALSE); end;
-
- procedure TFrmMain.Button10Click(Sender: TObject);
- const PLASMATECH_URL = 'http://plasmatech.com';
- begin ShellExecute( Handle, nil, PLASMATECH_URL, nil, nil, SW_SHOWNORMAL ); end;
-
- procedure TFrmMain.OrderBtnClick(Sender: TObject);
- const ORDER_URL = 'http://order.kagi.com/?J6&S';
- begin ShellExecute( Handle, nil, ORDER_URL, nil, nil, SW_SHOWNORMAL ); end;
-
- procedure TFrmMain.FormCreate(Sender: TObject);
- var imgl, imgl2: TImageList;
- function IsPalettedDisplay: Bool;
- var dc: HDC;
- begin
- dc := GetDC(0);
- result := ((Windows.GetDeviceCaps(dc, Windows.RASTERCAPS) and RC_PALETTE) <> 0);
- ReleaseDC(0,dc);
- end;
-
- function GetIndexOfExt( ext: String ): Integer;
- var shfi: TSHFileInfo;
- begin
- SHGetFileInfo( PChar(ext),0, shfi, Sizeof(TSHFileInfo), SHGFI_USEFILEATTRIBUTES or SHGFI_ICON );
- result := shfi.iIcon
- end;
-
- procedure AddIt( s: String; idx, offs: Integer );
- begin
- PTImageCombo1.AddItem( s, idx, offs );
- PTImageCombo2.AddItem( s, idx, offs );
- end;
- var s: String;
- begin
- Screen.Cursor := crHourglass;
- try
- PageControl1.ActivePage := WelcomeTsh;
-
- // Setup palette
- if IsPalettedDisplay then
- begin
- CreatePaletteStruct( mPalStruct );
- mhPal := Windows.CreatePalette( PLogPalette(@mPalStruct)^ );
- end;
-
- // Load rich text
- LoadRTF( OverviewRchtxt, 101 );
- LoadRTF( ExplorerRchtxt, 102 );
- LoadRTF( FileOpenRchedt, 103 );
- LoadRTF( ShellGetDisplayPathnameRchedt, 104 );
- LoadRTF( FolderBrowseRchedt, 105 );
- LoadRTF( ImageComboRchedt, 106 );
- LoadRTF( OrderRchedt, 107 );
- LoadRTF( CustomDrawTreeRchedt, 108 );
-
- // Setup "Image Combo" Page
- imgl := TImageList.Create(self);
- imgl.ShareImages := TRUE;
- imgl.Handle := ShellGetSystemImageList( ptsizLarge );
- PTImageCombo1.ImageList := imgl;
-
- imgl2 := TImageList.Create(self);
- imgl2.ShareImages := TRUE;
- imgl2.Handle := ShellGetSystemImageList( ptsizSmall );
- PTImageCombo2.ImageList := imgl2;
-
- // Just loading up the image combos with some arbitrary data
- AddIt( 'Text file', GetIndexOfExt('.txt'), 0 );
- AddIt( 'Document', GetIndexOfExt('.doc'), 1 );
- AddIt( 'HTML file', GetIndexOfExt('.htm'), 1 );
- AddIt( 'Bitmap', GetIndexOfExt('.bmp'), 2 );
- AddIt( 'GIF image', GetIndexOfExt('.gif'), 1 );
-
- PTImageCombo1.ItemIndex := 0;
- PTImageCombo2.ItemIndex := 1;
-
- // Setup "Custom Draw Tree" page
- PTTreeView1.FullExpand;
-
- // Setup "Splitter Panels" page
- Image3.Picture := PlasmaLogoImg.Picture;
- with Image1.Picture.Bitmap do
- begin
- Width := ToolbarImg.Width;
- Height := ToolbarImg.Height;
- Canvas.Brush.Color := clBtnFace;
- Canvas.BrushCopy( Rect(0,0,Width,Height), ToolbarImg.Picture.Bitmap, Rect(0,0,Width,Height), clFuchsia );
- end;
-
- // Setup "Extra" page
- UppercaseEdt.Text := AnsiUppercase(ParamStr(0));
- GetDisplayEdt.Text := ShellGetDisplayPathname(UppercaseEdt.Text);
-
- //
- s := VersionTxt.Caption;
- if (PTSHELLCONTROLS_VERSION mod 100) <> 0 then
- begin
- s := Format(s, [Format('%.02f',[PTSHELLCONTROLS_VERSION/100])]);
- if s[Length(s)]='0' then SetLength(s, Length(s)-1);
- end
- else
- s := Format(s, [IntToStr(PTSHELLCONTROLS_VERSION div 100)]);
- if (PTSHELLCONTROLS_PATCH > 0) then
- s := s + Char(Ord('a')+PTSHELLCONTROLS_PATCH-1);
- VersionTxt.Caption := s;
- VersionTxt.Autosize := FALSE; VersionTxt.Autosize := TRUE; // Force label to autosize
- VersionTxt.Left := (VersionTxt.Parent.ClientWidth - VersionTxt.Width) div 2;
-
- PTFolderBrowseDlg1.SelectedFolder.Pathname := GetCurrentDir;
-
- BaseTxt.Caption := 'Base is: '+ShellGetFriendlyNameFromIdList( nil, PTFolderBrowseDlg1.BaseFolder.IdList, ptfnNormal );
-
- PTTreeView1.OnPTCustomDraw := PTTreeView1PTCustomDraw;
- finally
- Screen.Cursor := Cursor;
- end;
- end;
-
- procedure TFrmMain.FormDestroy(Sender: TObject);
- begin
- if (mhPal <> 0) then Windows.DeleteObject(mhPal);
- end;
-
- procedure TFrmMain.TestOpenDlgBtnClick(Sender: TObject);
- var i, max: Integer;
- s: String;
- begin
- if PTOpenDlg1.Execute then
- if PTOpenDlg1.Files.Count>0 then
- begin
- if PTOpenDlg1.Files.Count>1 then
- begin
- s := 'Multiselect'#13;
- max := PTOpenDlg1.Files.Count-1;
- if max>25 then max:=25;
- for i := 0 to max do
- s := s + PTOpenDlg1.Files[i] + #13;
- if (max < PTOpenDlg1.Files.Count-1) then
- s := s + '...';
- ShowMessage( s );
- end;
- Edit1.Text := PTOpenDlg1.Files[0];
- end;
- end;
-
- procedure TFrmMain.Button13Click(Sender: TObject);
- begin
- PTSaveDlg1.Execute;
- end;
-
- procedure TFrmMain.FolderBrowseBtnClick(Sender: TObject);
- begin
- PTFolderBrowseDlg1.Status := 'This is an example of the TPTFolderBrowseDlg component.';
- if PTFolderBrowseDlg1.Execute then
- ShowMessage( Format( 'You selected:'#13' Filesystem Name: %s'#13' Display Name: %s',
- [ PTFolderBrowseDlg1.SelectedPathname,
- ShellGetFriendlyNameFromIdList(nil, PTFolderBrowseDlg1.SelectedFolder.IdList, ptfnInFolder)] ) );
- end;
-
- procedure TFrmMain.PTFolderBrowseDlg1SelChange(aSender: TObject; aNewSel: PItemIDList);
- begin
- if Assigned(aNewSel) then
- PTFolderBrowseDlg1.Status := ShellGetPathFromIdList(aNewSel)
- else
- PTFolderBrowseDlg1.Status := '';
- end;
-
-
- procedure TFrmMain.EnableTimerBtnClick(Sender: TObject);
- begin
- EnableTimerBtn.Down := not Timer1.Enabled;
- Timer1.Enabled := EnableTimerBtn.Down;
- PTTreeView1.Invalidate;
- end;
-
- var _lastpos: Integer = 0;
- _lastposdelta: Integer = +1;
-
- procedure TFrmMain.Timer1Timer(Sender: TObject);
- begin
- PTTreeView1.InvalidateNode( PTTreeView1.Items[_lastPos], FALSE, TRUE );
- _lastpos := _lastpos + _lastposdelta;
- if (_lastpos > PTTreeView1.Items.Count-1) then
- begin
- _lastpos := PTTreeView1.Items.Count-2;
- _lastposdelta := -1;
- end
- else if (_lastpos < 0) then
- begin
- _lastpos := 1;
- _lastposdelta := +1;
- end;
- PTTreeView1.InvalidateNode( PTTreeView1.Items[_lastPos], FALSE, TRUE );
- PTTreeView1.Update;
- end;
-
-
- procedure TFrmMain.PTTreeView1PTCustomDraw(aSender: TObject;
- aCD: TPTCustomDraw; aNode: TTreeNode);
- begin
- with CDT_GetNodeData(aNode) do
- begin
- aCD.Font := {.}Font;
- if aNode.Selected or aNode.DropTarget then
- if PTTreeView1.Focused then
- aCD.Font.Color := clHighlightText // Use the default item color when it is selected (but still change the font)
- else
- aCD.Font.Color := clBtnText
- else // Don't change the background color for selected items
- aCD.Brush.Color := {.}BkColor;
- end;
-
- if (Timer1.Enabled) then
- begin
- if aNode.AbsoluteIndex = _lastPos then
- begin
- aCD.NoDefaultDrawing := TRUE;
- Wash( aCD.Canvas, mhPal, Pointer(@mPalStruct), Active, aNode.DisplayRect(FALSE), clBlue, clWhite, FALSE );
- end
- end
- end;
-
- procedure TFrmMain.BoldBtnClick(Sender: TObject);
- begin CDT_DoFontStyle( PTTreeView1.Selected, BoldBtn.Down, fsBold ); end;
-
- procedure TFrmMain.ItalicBtnClick(Sender: TObject);
- begin CDT_DoFontStyle( PTTreeView1.Selected, ItalicBtn.Down, fsItalic ); end;
-
- procedure TFrmMain.UnderlineBtnClick(Sender: TObject);
- begin CDT_DoFontStyle( PTTreeView1.Selected, UnderlineBtn.Down, fsUnderline ); end;
-
- procedure TFrmMain.PTTreeView1Deletion(Sender: TObject; Node: TTreeNode);
- begin if Assigned(Node.Data) then TObject(Node.Data).Free; end;
-
- procedure TFrmMain.CDT_DoFontStyle( aNode: TTreeNode; aDown: Boolean; aStyle: TFontStyle );
- begin
- if not Assigned(aNode) then Exit;
- with CDT_GetNodeData(aNode).Font do
- begin
- if aDown then
- Style := Style + [aStyle]
- else
- Style := Style - [aStyle];
- PTTreeView1.InvalidateNode( aNode, FALSE, TRUE );
- PTTreeView1.Refresh;
- end;
- end;
-
- function TFrmMain.CDT_GetNodeData( aNode: TTreeNode ): TTvData;
- begin
- if not Assigned(aNode.Data) then
- aNode.Data := TTvData.Create(PTTreeView1.Font, PTTreeView1.Color);
- result := aNode.Data;
- end;
-
- procedure TFrmMain.CDT_OnDynamicMenuClick( aSender: TObject );
- begin ShowMessage( 'You clicked "' + (aSender as TMenuItem).Caption + '"' ); end;
-
- procedure TFrmMain.FontBtnClick(Sender: TObject);
- begin
- if Assigned(PTTreeView1.Selected) and Assigned(PTTreeView1.Selected.Data) then
- if FontDialog1.Execute then
- begin
- CDT_GetNodeData(PTTreeView1.Selected).Font := FontDialog1.Font;
- PTTreeView1.InvalidateNode( PTTreeView1.Selected, FALSE, TRUE );
- end;
- end;
-
- procedure TFrmMain.FgColorBtnClick(Sender: TObject);
- begin
- if Assigned(PTTreeView1.Selected) and Assigned(PTTreeView1.Selected.Data) then
- with CDT_GetNodeData( PTTreeView1.Selected ) do
- begin
- ColorDialog1.Color := {.}Font.Color;
- if ColorDialog1.Execute then
- {.}Font.Color := ColorDialog1.Color;
- end;
- end;
-
- procedure TFrmMain.BkColorBtnClick(Sender: TObject);
- begin
- if Assigned(PTTreeView1.Selected) and Assigned(PTTreeView1.Selected.Data) then
- with CDT_GetNodeData( PTTreeView1.Selected ) do
- begin
- ColorDialog1.Color := {.}BkColor;
- if ColorDialog1.Execute then
- {.}BkColor := ColorDialog1.Color;
- end;
- end;
-
- procedure TFrmMain.ClickMe1BtnClick(Sender: TObject);
- procedure SetItem( aNode: TTreeNode; afs: TFontStyles; aclr, abkclr: TColor );
- begin
- with CDT_GetNodeData(aNode) do
- begin
- Font.Style := afs;
- Font.Color := aclr;
- BkColor := abkclr;
- end;
- end;
-
- type TRec = record
- styles: TFontStyles;
- fgclr: TColor;
- bkclr: TColor
- end;
-
- const NR: array[0..6] of TRec = (
- (styles: [fsBold]; fgclr: clBlue; bkclr: clWhite ), // Fruit
- (styles: []; fgclr: clYellow; bkclr: clRed ), // Apple
- (styles: []; fgclr: clGreen; bkclr: clYellow ), // Pear
- (styles: [fsStrikeout]; fgclr: clWhite; bkclr: clGreen ), // Guava
- (styles: [fsBold]; fgclr: clGreen; bkclr: clWhite ), // Dogs
- (styles: [fsItalic]; fgclr: clWindowText; bkclr: clWindow ), // Shih Tzu
- (styles: [fsItalic]; fgclr: clGray; bkclr: clWindow ) // Jack Russel
- );
-
- var i: Integer;
- begin
- for i := Low(NR) to High(NR) do
- with NR[i] do
- SetItem( PTTreeView1.Items[i], styles, fgclr, bkclr );
- PTTreeView1.Invalidate;
- end;
-
- procedure TFrmMain.ResetBtnClick(Sender: TObject);
- var i: Integer;
- begin
- for i := 0 to PTTreeView1.Items.Count-1 do
- with CDT_GetNodeData(PTTreeView1.Items[i]) do
- begin
- Font := PTTreeView1.Font;
- BkColor := PTTreeView1.Color;
- end;
- PTTreeView1.Invalidate;
- end;
-
- procedure TFrmMain.ViewMitmClick(Sender: TObject);
- var i: Integer;
- begin
- for i := 0 to PopupMenu1.Items.Count-1 do // Delphi 2 needs this
- PopupMenu1.Items[i].Checked := FALSE;
-
- with (Sender as TMenuItem) do
- begin
- PTShellList1.ViewStyle := TViewStyle( {.}Tag );
- {.}Checked := TRUE;
- end;
- end;
-
- var gUniqueId: Integer = 0;
-
- procedure TFrmMain.PTTreeView1NodeContextMenu(aSender: TObject;
- aNode: TTreeNode; var aPos: TPoint; var aMenu: TPopupMenu);
- var m: TPopupMenu;
- begin
- aMenu := nil;
-
- m := NewPopupMenu( self, Format('Menu%d',[gUniqueId]), paLeft, FALSE, [
- NewItem(aNode.Text, 0, FALSE, TRUE, CDT_OnDynamicMenuClick, 0, Format('MItem%d',[gUniqueId])) ] );
- Inc( gUniqueId );
-
- try
- with PTTreeView1.ClientToScreen(aPos) do
- begin
- SendCancelMode(nil);
- m.PopupComponent := PTTreeView1;
- m.Popup( x, y );
- Application.ProcessMessages;
- // If you free the menu before messages get processed, which we do, you should call this first. Be aware
- // that by calling ProcessMessages, this event procedure could be re-entered.
- end;
- finally
- m.Free;
- end;
- end;
-
- procedure TFrmMain.PTTreeView1Change(Sender: TObject; Node: TTreeNode);
- var bv, iv, uv: Boolean;
- begin
- bv:=FALSE; iv:=FALSE; uv:=FALSE;
- if Assigned(Node) and Assigned(Node.Data) then
- with CDT_GetNodeData(Node) do
- begin
- bv := fsBold in Font.Style;
- iv := fsItalic in Font.Style;
- uv := fsUnderline in Font.Style;
- end;
- BoldBtn.Down := bv;
- ItalicBtn.Down := iv;
- UnderlineBtn.Down := uv;
- end;
-
- procedure TFrmMain.BaseBtnClick(Sender: TObject);
- var f: TPTFolderBrowseDlg;
- begin
- f := TPTFolderBrowseDlg.Create( self );
- try
- f.Status := 'Select a folder to act as base folder.';
- f.SelectedFolder := PTFolderBrowseDlg1.BaseFolder;
- if f.Execute then
- begin
- PTFolderBrowseDlg1.BaseFolder := f.SelectedFolder;
- BaseTxt.Caption := 'Base is: '+ShellGetFriendlyNameFromIdList( nil, f.SelectedFolder.IdList, ptfnNormal );
- PTFolderBrowseDlg1.SelectedFolder := f.SelectedFolder;
- end;
- finally
- f.Free;
- end;
- end;
-
- procedure TFrmMain.ToolbarImgMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
- const ComponentNames: array[0..13] of String = (
- 'TPTShellTree'#13#13'Enhanced Explorer tree view.',
- 'TPTShellList'#13#13'Enhanced Explorer list view.',
- 'TPTShellCombo'#13#13'Explorer combo box.',
- 'TPTOpenDlg'#13#13'Powerful replacement for TOpenDlg.',
- 'TPTSaveDlg'#13#13'Powerful replacement for TSaveDlg.',
- 'TPTFolderBrowseDlg'#13#13'Powerful replacement for SHBrowseForFolder.',
- 'TPTFrame'#13#13'Non-windowed frame control with 11 frame styles.',
- 'TPTGroup'#13#13'Windowed TPanel replacement with 11 frame styles.',
- 'TPTSplitter'#13#13'Powerful and simple splitter control.',
- 'TPTImageCombo'#13#13'Combo box with image and indent'#13'level per item.',
- 'TPTSysFolderDlg'#13#13'Encapsulation of the system''s'#13'built-in SHBrowseForFolder function.',
- 'TPTCombobox'#13#13'Combo box control with events for'#13'OnDeleteItem, OnCloseUp, OnSelEndOk and OnSelEndCancel.',
- 'TPTTreeView'#13#13'Enhanced tree view control with Internet Explorer 3/4 features.',
- 'TPTListView'#13#13'Enhanced list view control with Internet Explorer 3/4 features.'
- );
- var item: Integer;
- begin
- item := (x-8) div 28;
- if (item < Low(ComponentNames)) or (item > High(ComponentNames)) then
- begin
- Application.CancelHint;
- ToolbarImg.Hint := '';
- end
- else
- begin
- if ToolbarImg.Hint <> ComponentNames[item] then
- begin
- Application.CancelHint;
- ToolbarImg.Hint := ComponentNames[item];
- end;
- end;
- end;
-
-
- end.
-
-